@{
    ViewBag.Title = "用户管理";
}
@section head{
   <script type="text/javascript">
       $(document).ready(function () {
           $('.btnSearch').click(function () {
               mainSearch('.search_box :input');
           });
       });
       function lockformat(value, row, index) {
           return value ? '锁定' : '正常';
       }
       function on_close(key) {
           $('#details').datagrid('reload');
       }
       function onDeleteData() {
           $('#details').datagrid('reload');
       }
       function roleformatter(value, row, index) {
           return '<a href="javascript:show_fullscreen_dialog(\'@Url.Action("Index", "ManagerToRole")?UserName=' + row.UserName + '\',on_close,\'role\')" style=" display:block" >' + value + '</a>';
       }
       function onlingformatter(value, row, index) {
           var ret = null;
           if (value > 0) {
               ret = '<a href="javascript:removeOnline(\'' + row.UserName + '\')" style=" display:block" >在线(' + value + ')</a>';
           }
           else {
               ret = '离线';
           }
           return ret;
       }

       function removeOnline(userName) {
           $.messager.confirm('确认', '确实要将用户踢下线吗？', function (r) {
               if (r) {
                   postModal('@Url.Action("KickOut")', { UserName: userName }, function (r) {
                       if (r.success) {
                           $('#details').datagrid('reload');
                       }
                   });
               }
           });
       }

       function removeSelectOnline() {
           var selected=$('#details').datagrid('getSelections');
           if (selected.length == 0) {
               show_msg('请先选择要下线的用户', 'bulb');
               return;
           }
           var ids = '';
           for (var i = 0; i < selected.length; i++) {
               ids += ',' + selected[i].UserName;
           }
           ids = ids.substring(1);
           removeOnline(ids);
       }

       function cmdformat(value, row, index) {
           var ret='';
           if(row.ManagerType!=3) ret+='<a href="javascript:show_fullscreen_dialog(\'@Url.Action("Index", "Authority")?usertype=1&usercode=' + row.UserName + '\')"><img src="@Url.Content("~/Content/Images/Icons/authority.png")" title="权限管理"/></a>';
           ret+= ' &nbsp;<a href="javascript:show_fullscreen_dialog(\'' + serverUrl.edit + '?UserName=' + row.UserName + '\',on_close,\'edit\')"><img src="@Url.Content("~/Content/Images/Icons/edit.png")" title="修改"/></a>';
           ret+= ' &nbsp;<a href="javascript:Del(\'' + row.UserName + '\',onDeleteData)"><img src="@Url.Content("~/Content/Images/Icons/delete.png")" title="删除"/></a>';
           return ret;
       }
       function typeformat(value, row, index) {
          var ManagerType=@Html.Raw(new OA.Mvc3.Controllers.DictionaryController().GetChilds("ManagerType"));
          return dicformat(ManagerType,value);
       }
   </script>
}
@section body{
<body>
<div class="easyui-layout" data-options="fit:true">
    <div region="north" border="false">
        <div class="navigation">@ViewBag.CurrentPath</div>
        <div class="tools_box">
	        <div class="tools_bar">
                <div class="left">
                   <a href="javascript:search_click()" id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true ">查询</a>  
                   <a href="javascript:show_fullscreen_dialog(serverUrl.add,on_close,'add')" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true ">添加</a>  
                   <a href="javascript:DeleteSelecteds($('#details').datagrid('getSelections'),'UserName',onDeleteData)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">批量删除</a>
                   <a href="javascript:removeSelectOnline()" class="easyui-linkbutton" data-options="iconCls:'icon-disconnect',plain:true">下线</a>
                </div>
            </div>
            <div class="search_box">
			    用户名：<input type="text" name="UserName" class="txtSearchInput" />
                姓名：<input type="text" name="RealName" class="txtSearchInput" />
                部门：<input type="text" name="Group.GroupName" class="txtSearchInput" />
                <input type="submit" value="查询" class="btnSearch"/>
		    </div>
        </div>
    </div> 
    <div region="center" border="false">
        <table class="easyui-datagrid" id="details" data-options="fit:true,rownumbers:true,singleSelect:false,
          pagination:true,border:true,url:serverUrl.list">
           <thead data-options="frozen:true"> 
              <tr>
                   <th data-options="field:'id',checkbox:true"></th>
                   <th data-options="field:'UserName',sortable:true,width:100">用户名</th>
              </tr>
           </thead>
           <thead>  
               <tr>  
                   <th data-options="field:'RealName',sortable:true,width:100">姓名</th>
                   @if(OA.BLL.LoginUser.LoginManager.ManagerType== OA.Common.EnumType.ManagerType.Super){
                    <th data-options="field:'ManagerType',width:100,formatter:typeformat">用户类型</th>
                    }
                   <th data-options="field:'GroupName',width:100">部门</th>
                   <th data-options="field:'Email',sortable:true,width:150,formatter:emailFormat">电子邮箱</th>
                   <th data-options="field:'IsLock',sortable:true,width:80,align:'center',formatter:lockformat" >账户状态</th>
                   <th data-options="field:'RoleCount',width:100,align:'center',formatter:roleformatter">角色列表</th>
                   <th data-options="field:'Onlines',sortable:false,width:100,align:'center',formatter:onlingformatter">在线状态</th>
                   <th data-options="field:'CreatTime',sortable:true,width:150">创建时间</th>
                   <th data-options="field:'cmd',width:100,align:'right',formatter:cmdformat">操作</th>
               </tr>  
           </thead>  
        </table>
    </div>
</div>
</body>
}